<?=$this->header()?>


    <?=$this->menu("projects")?>


    <h1><?=$this->message("label.header", _Project::BUNDLE)?></h1>


    <? /* Breadcrums route & project info display */ ?>
    <?=$this->route(
        array(
            array(
                "name"=>$this->message("label.category.header", _Project::BUNDLE),
                "href"=>"project/category/list"
            ),
            $this->category($this->projectListForm->getId())
        ), // Route display
        $this->projectListForm,                             // ListForm (for project info, see float right)
        $this->projects($this->projectListForm)->getRows()) // The total amount of projects
    ?>


    <? /* Show status messages */ ?>
    <?=$this->messages(_Core::BUNDLE)?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null)?>


    <form id="<?=get_class($this->projectListForm)?>"
          method="post"
          action="project/list"
          onsubmit="return confirmDelete('<?=$this->message("message.confirm.delete", _Core::BUNDLE)?>', this)">


        <? /* Show the Search & Filter Panel */ ?>
        <?=$this->panel(
            "project/edit?projectI18n->project->categoryId=".$this->projectListForm->getId(), // Add New URL
            $this->projectListForm, // ListForm
            array(                  // Filter fields
                ProjectI18nPeer::NAME=>$this->message("prompt.name", _Project::BUNDLE),
                ProjectI18nPeer::INTRO=>$this->message("prompt.intro", _Project::BUNDLE),
                ProjectI18nPeer::DESCRIPTION=>$this->message("prompt.description", _Project::BUNDLE),
                ProjectPeer::URL=>$this->message("prompt.url", _Project::BUNDLE),
                ProjectPeer::DATE=>$this->message("prompt.date", _Project::BUNDLE),
                ProjectI18nPeer::INSERT_DATE=>$this->message("choose.created", _Core::BUNDLE),
                ProjectI18nPeer::MODIFIED_DATE=>$this->message("choose.modified", _Core::BUNDLE),
                ProjectI18nPeer::ACTIVE=>$this->message("choose.active", _Core::BUNDLE)
            )
        )?>


        <? /* Start output buffering in case there are no results */ ?>
        <?$this->start()?>


        <table class="list" cellspacing="0" cellpadding="0">
        <tr>
            <th class="checkbox"></th>
            <th class="narrow"></th>

            <? /* Hide i18n if disabled */ ?>
            <? if($this->param(_Core::I18N)): ?>
                <th class="narrow" title="<?=$this->message("title.language", _Core::BUNDLE)?>">
                    <?=$this->message("label.language", _Core::BUNDLE)?>
                </th>
            <? endif; ?>

            <th>
                <?=$this->TH(
                    $this->projectListForm, // ListForm
                    ProjectI18nPeer::NAME,  // Sort Field
                    $this->message("prompt.name", _Project::BUNDLE)                  // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->projectListForm, // ListForm
                    ProjectPeer::DATE,      // Sort Field
                    $this->message("prompt.date", _Project::BUNDLE)                  // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->projectListForm,                          // ListForm
                    ProjectI18nPeer::MODIFIED_DATE,                  // Sort Field
                    $this->message("choose.modified", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->projectListForm,                         // ListForm
                    ProjectI18nPeer::INSERT_DATE,                   // Sort Field
                    $this->message("choose.created", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow" title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                <?=$this->TH(
                    $this->projectListForm,                       // ListForm
                    ProjectI18nPeer::ACTIVE,                      // Sort Field
                    $this->message("label.active", _Core::BUNDLE) // Header Name
                )?>
            </th>

            <? /* Hide i18n if disabled */ ?>
            <? if($this->param(_Core::I18N)): ?>
                <th class="narrow" title="<?=$this->message("title.language.available", _Core::BUNDLE)?>">
                    <?=$this->message("label.language.available", _Core::BUNDLE)?>
                </th>
            <? endif; ?>

            <th class="buttons"></th>
        </tr>

        <? foreach($this->projects($this->projectListForm)->getItems() as $projectI18n): ?>

            <? /* Display the default language project */ ?>
            <tr class="ctrl">
                <td class="checkbox">
                    <input type="checkbox"
                           name="items[]"
                           value="<?=$projectI18n->getProjectI18nId()?>"
                           <?=in_array($projectI18n->getProjectI18nId(), $this->projectListForm->getItems()) ? " checked=\"checked\"" : ""?> />
                </td>
                <td>
                    <? if($projectI18n->getProject()->getImageId() > 0): ?>
                    <a title="<?=$this->message("title.image", _Core::BUNDLE)?>" href="image?id=<?=$projectI18n->getProject()->getImageId()?>">
                        <?=$this->thumbnail($projectI18n->getProject()->getThumbnailId())?>
                    </a>
                    <? endif; ?>
                </td>

                <? /* Hide i18n if disabled */ ?>
                <? if($this->param(_Core::I18N)): ?>
                    <td title="<?=$this->message("title.language", _Core::BUNDLE)?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($projectI18n->getLanguage()->getCode()).".png")?>"
                             width="16" height="11" alt="<?=$projectI18n->getLanguage()->getName()?>"
                             title="<?=$projectI18n->getLanguage()->getName()?>" class="flag" />

                    </td>
                <? endif; ?>

                <td><?=$this->truncateNicely($projectI18n->getName(), 40, 50, "...")?></td>
                <td><?=$projectI18n->getProject()->getDate(_Core::FORMAT_DATE)?></td>
                <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$projectI18n->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                    <?=$projectI18n->getModifiedDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$projectI18n->getInsertDate(_Core::FORMAT_DATETIME)?>">
                    <?=$projectI18n->getInsertDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                    <?=$this->message("label." . ($projectI18n->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                </td>

                <? /* Hide i18n if disabled */ ?>
                <? if($this->param(_Core::I18N)): ?>
                    <td title="<?=$this->message("title.language.available", _Core::BUNDLE)?>">

                        <? /* Only show available languages when item language same as CMS default language) */ ?>
                        <? if($projectI18n->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)) { ?>
                            <? foreach($projectI18n->getAvailableLanguages() as $language) { ?>
                                <a href="project/edit?projectI18n->projectId=<?=$projectI18n->getProjectId()?>&amp;projectI18n->languageCode=<?=$language->getCode()?>">
                                    <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($language->getCode()).".png")?>"
                                         width="16" height="11"
                                         alt="<?=$language->getName()?>"
                                         title="<?=$this->message("title.translate.item", _Core::BUNDLE)?> (<?=$language->getName()?>)."
                                         class="flag" />
                                 </a>
                            <? } ?>
                        <? } ?>

                    </td>
                <? endif; ?>

                <td class="buttons">

                    <input type="button"
                           onclick="to('project/edit?projectI18n->projectI18nId=<?=$projectI18n->getProjectI18nId()?>')"
                           class="button"
                           value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />

                    <input type="button"
                           onclick="del(<?=$projectI18n->getProjectI18nId()?>, '<?=get_class($this->projectListForm)?>')"
                           class="button"
                           value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                </td>
            </tr>

            <? /* Loop through the foreign languages when i18n enabled & language selectbox is on ALL */?>
            <? if($this->param(_Core::I18N) && strlen($this->projectListForm->getLanguage()) == 0 && strlen($this->projectListForm->getQuery()) == 0): ?>

                <?
                $i18nProjects = $projectI18n->getForeignProjectI18ns($this->param(_Core::DEFAULT_LANGUAGE));
                for($i=0; $i<count($i18nProjects); $i++) { ?>
                <tr class="ctrlsub">
                    <td class="checkbox">
                        <input type="checkbox"
                           name="items[]"
                           value="<?=$i18nProjects[$i]->getProjectI18nId()?>"
                           <?=in_array($i18nProjects[$i]->getProjectI18nId(), $this->projectListForm->getItems()) ? " checked=\"checked\"" : ""?> />
                    </td>
                    <td></td>
                    <td title="<?=$this->message("title.language", _Core::BUNDLE)?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($i18nProjects[$i]->getLanguage()->getCode()).".png")?>"
                             width="16" height="11"
                             alt="<?=$i18nProjects[$i]->getLanguage()->getName()?>"
                             title="<?=$this->message("title.translation", _Core::BUNDLE)?> (<?=$i18nProjects[$i]->getLanguage()->getName()?>)" />

                    </td>
                    <td class="translation">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/arrow_merge.png")?>"
                             title="<?=$this->message("title.translation", _Core::BUNDLE)?> (<?=$i18nProjects[$i]->getLanguage()->getName()?>)"
                             width="16" height="16" alt="" class="arrow" />
                        <?=$this->truncateNicely($i18nProjects[$i]->getName(), 30, 40, "...")?>

                    </td>
                    <td></td>
                    <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$i18nProjects[$i]->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                        <?=$i18nProjects[$i]->getModifiedDate(_Core::FORMAT_DATE)?>
                    </td>
                    <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$i18nProjects[$i]->getInsertDate(_Core::FORMAT_DATETIME)?>">
                        <?=$i18nProjects[$i]->getInsertDate(_Core::FORMAT_DATE)?>
                    </td>
                    <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                        <?=$this->message("label." . ($i18nProjects[$i]->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                    </td>
                    <td></td>
                    <td class="buttons">

                        <input type="button"
                               onclick="to('project/edit?projectI18n->projectI18nId=<?=$i18nProjects[$i]->getProjectI18nId()?>')"
                               class="button"
                               value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />

                        <input type="button"
                               onclick="del(<?=$i18nProjects[$i]->getProjectI18nId()?>, '<?=get_class($this->projectListForm)?>')"
                               class="button"
                               value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                    </td>
                </tr>
                <? } ?>

            <? endif; ?>

        <? endforeach; ?>

        </table>


        <? /* Edit/Action Bar for checkboxed */ ?>
        <?=$this->edit(
            $this->projectListForm, // ListForm
            array(                // The actions
                "activate"=>$this->message("choose.activate", _Core::BUNDLE),
                "deactivate"=>$this->message("choose.deactivate", _Core::BUNDLE),
                "delete"=>$this->message("choose.delete", _Core::BUNDLE)
            )
        )?>


        <? /* End output buffering */ ?>
        <?$this->end(
            $this->projectListForm,                         // ListForm
            "project/edit?projectI18n->project->categoryId=".$this->projectListForm->getId(), // Add New URL
            $this->projects($this->projectListForm)->getRows() // The total amount of projects
        )?>


    </form>

<?=$this->footer()?>